import 'package:hinge/common/index.dart';
import 'package:mobx/mobx.dart';

part 'personal_store.g.dart';

class PersonalStore = _PersonalStore with _$PersonalStore;

abstract class _PersonalStore with Store {
  @observable
  bool isLoading = false;

  @observable
  ObservableList<PerfumeModel> userCollections =
      ObservableList<PerfumeModel>.of([]);

  @observable
  ObservableList<PerfumeModel> userLikes = ObservableList<PerfumeModel>.of([]);

  @action
  Future<void> loadUserCollections(int userId) async {
    isLoading = true;
    try {
      // 获取用户收藏的香水列表
      final collections = await LikeCollectionService.getUserCollections(
        userId,
      );
      userCollections = ObservableList.of(collections);
    } catch (e) {
      print('Error loading user collections: $e');
    } finally {
      isLoading = false;
    }
  }

  @action
  Future<void> loadUserLikes(int userId) async {
    isLoading = true;
    try {
      // 获取用户点赞的香水列表
      final likes = await LikeCollectionService.getUserLikes(userId);
      userLikes = ObservableList.of(likes);
    } catch (e) {
      print('Error loading user likes: $e');
    } finally {
      isLoading = false;
    }
  }

  @action
  void reset() {
    userCollections.clear();
    userLikes.clear();
  }
}
